<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>自助消费</title>
		<meta name="keywords" content="">
		<meta name="description" content="">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<meta name="mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no,email=no,address=no" />
		<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
		<link rel="stylesheet" href="../css/zy_common.css" />
		<link rel="stylesheet" href="../css/zy_base.css" />		
		<style>
			html,body{
				overflow: hidden;
			}
		</style>
	</head>
	<body>
		<div class="rechargeBox color-333 font-15" style="margin-top: 0.2rem;">
			<p>消费金额</p>
			<p class="border_bottom">
				<span style="font-size: 0.47rem;margin-right: 0.2rem;vertical-align: sub;">￥</span>
				<input type="number" id="money" value="" placeholder="请输入消费金额"/>
			</p>
		</div>
		<div class="confirm" style="margin-top: 0.85rem;">确认</div>		
	</body>
</html>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/tooltipbox.js"></script>
<script type="text/javascript" src="../js/dlc.js"></script>
<script>
	var off=0;
	$(function(){
		$('.confirm').click(function(){
			var money=$('#money').val();
			if(isNull(money)){
				tooltipbox.show('请输入消费金额')
			}else if(money<1){
				tooltipbox.show('消费金额须大于1')
			}else{
				if(off){
					return false;
				}
				off=1;
				tooltipbox.show("请稍后...",'bottom',1000)
				$.ajax({
			        type:'post',
			        data:{type:5,money:money},
			        url:  dlcUrl()+'user_api/wxpay',
			        dataType: 'json',
			        success: function(result){
			        	/*alert(JSON.stringify(result));*/
			        	if(result.code=='1'){
				        	jsApiParameters=result.data;
				        	// order_id=result.data.order_id;
				        	callpay();
			        	}

			        },error:function(err){
			        	/*alert(JSON.stringify(err));*/
			        	tooltipbox.show('出错了')
			        	off=0;
			        }
				});
			}
		})
	})


 	// 提交支付信息
	var jsApiParameters = {}; 
	
	//调用微信JS api 支付
	function jsApiCall()
	{
		WeixinJSBridge.invoke(
			'getBrandWCPayRequest',
			jsApiParameters, // 提交的支付信息
			function(res){
				WeixinJSBridge.log(res.err_msg);
//				alert(JSON.stringify(res));
				if(res.err_msg == 'get_brand_wcpay_request:ok'){
					tooltipbox.show('支付成功');
					setTimeout(function(){
						location.href='index.php';
					},1500)
				}else{
					off=0;
					tooltipbox.show("取消支付")
				}
			}
		);
	}
	//调用微信 支付
	function callpay()
	{
		if (typeof WeixinJSBridge == "undefined"){
			if( document.addEventListener ){
				document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
				
			}else if (document.attachEvent){
				document.attachEvent('WeixinJSBridgeReady', jsApiCall);
				document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
			}
		}else{
			jsApiCall();
		}
	}
</script>